package com.heqiang.controller;


import com.heqiang.utils.BaseController;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class MyExceptionController extends BaseController implements ErrorController {

	@Override
	public String getErrorPath() {
		return "/error";
	}

	@RequestMapping(value = "/error")
	public ModelAndView handleError(HttpServletRequest request) {
		Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
		String path = "";
		switch (statusCode) {
			case 404:
				path = "/admin/404";
				break;
			case 500:
				path = "/admin/500";
				break;
			default:
				path = "/admin";
				break;
		}
		return goView(path);
	}
}
